//
//  HomeDataTool.m
//
//
//  Created by jiaoxiu－004 on 14/11/12.
//  Copyright (c) 2014年 北京娇羞科技有限公司. All rights reserved.
//

#import "HomeDataTool.h"
#import "JXAppInfo.h"
#import "HomeDataInfo.h"
#import "HomeTabInfo.h"
#import "ReviewsResult.h"
#import "JXBaseRequest.h"
#import "ProductDetail.h"
#import "ProdComtList.h"
#import "ShakeList.h"
#import "Shake.h"
#import "HomeFirstPageInfo.h"

@implementation HomeDataTool
+ (void)homeOldDataInfoWithParam:(NSDictionary *)param success:(void (^)(HomeDataInfo *result))success failure:(void (^)(NSError *error))failure{
    [self postWithUrl:[NSString stringWithFormat:@"%@index/homelist",BASE_URL] param:param hasT:NO resultClass:[HomeDataInfo class] success:success failure:failure];
}
+ (void)homeDataInfoWithParam:(NSDictionary *)param success:(void (^)(HomeTabInfo *result))success failure:(void (^)(NSError *error))failure;{
    [self postWithUrl:[NSString stringWithFormat:@"%@index/homePage",BASE_URL] param:param hasT:NO resultClass:[HomeTabInfo class] success:success failure:failure];
}

+ (void)appInfo:(void (^)(JXAppInfo *result))success failure:(void (^)(NSError *error))failure{
    JXBaseRequest *request = [[JXBaseRequest alloc]init];
    [self postWithUrl:[NSString stringWithFormat:@"%@app/upgrade",BASE_URL] param:[request keyValues] hasT:NO resultClass:[JXAppInfo class] success:success failure:failure];
}

+ (void)reviewsDataWithId:(NSString *)reviewsId lastComtId:(NSString *)lastComtId success:(void (^)(ReviewsResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:reviewsId forKey:@"reviewsId"];
    [param setObject:lastComtId forKey:@"lastComtId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@index/labelDetail",BASE_URL] param:param hasT:NO resultClass:[ReviewsResult class] success:success failure:failure];
}


+ (void)replyCommentWithReplyUrl:(NSString *)replyUrl ReplyType:(NSString *)replyType replyMainId:(NSString *)replyMainId commentId:(NSString *)commentId replyContent:(NSString *)replyContent userIdOther:(NSString *)userIdOther commentType:(NSString *)commentType success:(void (^)(CommentInfo *result))success failure:(void (^)(NSError *error))failure{
    
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:replyMainId forKey:replyType];
    [param setObject:[Utils isBlankString:commentId]?@"":commentId forKey:@"commentId"];
    [param setObject:[Utils isBlankString:replyContent]?@"":replyContent forKey:@"commentContent"];
    [param setObject:[Utils isBlankString:userIdOther]?@"":userIdOther forKey:@"userIdOther"];
    [param setObject:[Utils isBlankString:commentType]?@"0":commentType forKey:@"commentType"];
    
    [self postWithUrl:[NSString stringWithFormat:@"%@%@",BASE_URL,replyUrl] param:param hasT:YES resultClass:[CommentInfo class] success:success failure:failure];
}

+ (void)getProdDetailWithProdId:(NSString *)prodId success:(void (^)(ProductDetail *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:prodId forKey:@"productId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/detail",BASE_URL] param:param hasT:![Utils isBlankString:TOKEN] resultClass:[ProductDetail class] success:success failure:failure];
}

+ (void)getProdComtListWithProdId:(NSString *)prodId lastComtId:(NSString *)lastComtId success:(void (^)(ProdComtList *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:prodId forKey:@"prodId"];
    [param setObject:lastComtId forKey:@"lastComtId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/comment",BASE_URL] param:param hasT:NO resultClass:[ProdComtList class] success:success failure:failure];
}


+ (void)collectProdWithProdId:(NSString *)prodId isMark:(BOOL)isMark success:(void (^)(JXBaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:prodId forKey:@"prodId"];
    [param setObject:isMark?@"1":@"0" forKey:@"isMark"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/mark",BASE_URL] param:param hasT:YES resultClass:[JXBaseResponse class] success:success failure:failure];
}

+ (void)doPraiseWithReviewsId:(NSString *)reviewsId success:(void (^)(JXBaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:reviewsId forKey:@"reviewsId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@reviews/praise",BASE_URL] param:param hasT:NO resultClass:[JXBaseResponse class] success:success failure:failure];
}

+(void)getFirstHomePageData:(void (^)(HomeFirstPageInfo *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@index/firstPage",BASE_URL] param:param hasT:NO resultClass:[HomeFirstPageInfo class] success:success failure:failure];
}

+(void)setADIDFA:(NSString *)idfa{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:idfa forKey:@"idfa"];
    [self postWithUrl:[NSString stringWithFormat:@"%@app/advertis",BASE_URL] param:param hasT:NO resultClass:[JXBaseResponse class] success:nil failure:nil];

}

+(void)getSunSignleWithSunSingleId:(NSString *)sunSingleId productId:(NSString *)productId createTime:(NSString *)createTime success:(void (^)(HomeTabInfo *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:sunSingleId forKey:@"sunSignleId"];
    [param setObject:productId forKey:@"productId"];
    [param setObject:createTime forKey:@"createTime"];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/sunSignle",BASE_URL] param:param hasT:NO resultClass:[HomeTabInfo class] success:success failure:failure];
}

+ (void)delMarkProdWithProdIds:(NSString *)prodIds success:(void (^)(JXBaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:prodIds forKey:@"prodIds"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/delMark",BASE_URL] param:param hasT:YES resultClass:[JXBaseResponse class] success:success failure:failure];
}

+ (void)getUserShakeList:(void(^)(ShakeList *result))success failure:(void (^)(NSError *error))failure{
    [self postWithUrl:[NSString stringWithFormat:@"%@user/shakeList",BASE_URL] param:nil hasT:YES resultClass:[ShakeList class] success:success failure:failure];
}


+ (void)userShake:(void(^)(Shake *result))success failure:(void (^)(NSError *error))failure{
    [self postWithUrl:[NSString stringWithFormat:@"%@user/shake",BASE_URL] param:nil hasT:YES resultClass:[Shake class] success:success failure:failure];
}
@end
